package com.tledu.production.core.tag;

import com.tledu.production.constant.SessionConstant;
import com.tledu.production.model.system.SysUser;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.util.List;

/**
 * 安全标签
 *
 * @author Antg
 * @date 2021/8/20  10:12
 */
public class securityTag extends SimpleTagSupport {

    private String res;//资源连接

    @Override
    public void doTag() throws JspException, IOException {
        //获取session
        PageContext pc = (PageContext) this.getJspContext();
        HttpSession session = pc.getSession();

        //如果是超级管理员就不拦截
        SysUser user = (SysUser) session.getAttribute(SessionConstant.LOGINUSER);
        if (user.getSysRole().getRoleName().equals("超级管理员")) {
            this.getJspBody().invoke(null);
            return;
        }

        List<String> auth = (List<String>) session.getAttribute(SessionConstant.AUTH);

        //有权限则显示
        if (auth.contains(res)) {
            this.getJspBody().invoke(null);
        } else {
            System.out.println("没有权限---->" + res);
        }
    }

    public String getRes() {
        return res;
    }

    public void setRes(String res) {
        this.res = res;
    }
}
